package com.example.springboot.mapper;

import com.example.springboot.entity.Collect;
import com.example.springboot.entity.Post;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CollectMapper {
    @Select("select id,collect_id as collectId,collected_id as collectedId,update_time as updateTime,is_collect as isCollect  from user_collects where collect_id = #{collectId} and collected_id = #{collectedId}")
    Collect isEmpty (Collect collect);
    @Insert("insert into user_collects(collect_id,collected_id,is_collect) values(#{collectId},#{collectedId},#{isCollect})")
    void insertCollect(Collect collect);
    @Update("update user_collects set is_collect = #{isCollect} where collect_id = #{collectId} and collected_id = #{collectedId}")
    void updateCollect(Collect collect);

    List<Post> getCollectPostByUserId(Integer id, Integer offset);

    List<Post> getFollowPostByUserId(Integer id, Integer offset);

    List<Post> getUserPostByUserId(Integer id, Integer offset);
    @Select("select count(*) from user_collects where collect_id = #{id}")
    Integer getCollectPostNumByUserId(Integer id);
    @Select("select count(*) from blog_posts where author_id = #{id}")
    Integer getUserPostNum(Integer id);
}
